const express = require('express');
const cors = require('cors');

const app = express();

app.use(express.json()); // 支持 JSON 请求体
app.use(cors());

app.get('/greet/:name', (req, res) => {
    const name = req.params.name; // 获取名为'name'的路由参数
    res.send(`Hello, ${name}`);
});

app.get('/send_register_verification_code', (req, res) => {
    const phoneNumber = req.query.phoneNumber; // 获取名为'phoneNumber'的查询字符串参数
    const verificationCode = Math.floor(100000 + Math.random() * 900000);
    console.log("发送号码是：", phoneNumber, "；生成的6位验证码是：", verificationCode);
    res.json({code: 200, message: '发送成功', data: null, timestamp: new Date().getTime()});
});

app.post('/register', (req, res) => {
    console.log(req.body);
    res.json({code: 200, message: '注册成功', data: null, timestamp: new Date().getTime()});
});

app.listen(3000, () => {
    console.log('Express server running at http://localhost:3000');
});
